﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using AlchemyAPI;
using Sentiment;
using Twitterizer;
using BLL;
using Logic.Enums;


using System.Configuration;

namespace MvcApplication1.Controllers
{
    public class TestController : Controller
    {
        public ActionResult Test1()
        {
            
            
            // Create an AlchemyAPI object.
            AlchemyAPI.AlchemyAPI alchemyObj = new AlchemyAPI.AlchemyAPI();

            // Extract sentiment for a web URL.
            string json = alchemyObj.URLGetTextSentiment("http://www.techcrunch.com/");
            var res = json.FromJson<RequestRes>();


            // Extract sentiment from a text string.
            json = alchemyObj.TextGetTextSentiment("Hello there, my name is Bob Jones.  I live in the United States of America.  Where do you live, Fred?");
            res = json.FromJson<RequestRes>();


            // Load a HTML document to analyze.
            //StreamReader streamReader = new StreamReader("data/example.html");
            //string htmlDoc = streamReader.ReadToEnd();
            //streamReader.Close();


            // Extract sentiment from a HTML document.
            //xml = alchemyObj.HTMLGetTextSentiment(htmlDoc, "http://www.test.com/");
            //Console.WriteLine(xml);


            // Extract named entities with entity-targeted sentiment.
            //AlchemyAPI_EntityParams entityParams = new AlchemyAPI_EntityParams();
            //entityParams.setSentiment(true);
            //xml = alchemyObj.TextGetRankedNamedEntities("Bryan Adams' genius is unsurpassed.", entityParams);
            //Console.WriteLine(xml);


            //// Extract keywords with keyword-targeted sentiment.
            //AlchemyAPI_KeywordParams keywordParams = new AlchemyAPI_KeywordParams();
            //keywordParams.setSentiment(true);
            //xml = alchemyObj.TextGetRankedKeywords("Bryan Adams' genius is unsurpassed.", keywordParams);
            //Console.WriteLine(xml);


            return Json(res, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Test2()
        {
            OAuthTokens tokens = new OAuthTokens { ConsumerKey = ConfigurationManager.AppSettings["TwitterToken"], ConsumerSecret = ConfigurationManager.AppSettings["TwitterTokenSecret"] };

            var accounts = Accounts.Get().Select();
            foreach (var a in accounts)
            {
                if (a.Type == AccountType.Twitter)
                {
                    tokens.AccessToken = a.TwKey;
                    tokens.AccessTokenSecret = a.TwSecret;
                    TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(tokens, "Hello, #Twitterizer");
                    if (tweetResponse.Result == RequestResult.Success)
                    {
                        // Tweet posted successfully!
                    }
                    else
                    {
                        // Something bad happened
                    }
                }
            }

            return null;
        }
    }
}
